package com.example.kehoobackend.controller;

import com.example.kehoobackend.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@Validated
@CrossOrigin
@RestController
public class EmailController {
    @Autowired
    private EmailService emailService;

    /**
     * 获取邮箱验证码
     *
     * @param email 邮箱
     * @return CommonResponse<String>
     */
    @GetMapping("/user/email/code")
    public String getEmailCode(
            @RequestParam("email") String email) {
        return emailService.sendCode(email);
    }

    /**
     * 验证邮箱验证码
     *
     * @param token 令牌
     * @param code  验证码
     * @return CommonResponse<Boolean>
     */
    @GetMapping("/user/email/verify")
    public Boolean verifyEmailCode(
            @RequestParam("token") String token,@RequestParam("code") String code) {
        return emailService.verifyCode(token, code);
    }


}
